home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / AppleScript / Development Tools / Sample Code / 7Edit 3.1 / Sources / SVAEObjectsExist.c < prev    next >
Encoding:
Text File  |  1995-11-20  |  2.0 KB  |  80 lines  |  [TEXT/CWIE]

  1. // SVAEObjectsExist.c
  2. //
  3. // 7Edit 3.1d1. Original version by Jon Lansdell and Nigel Humphreys.
  4. // 3.1 updates by Greg Sutton.
  5. // ©Apple Computer Inc 1995, all rights reserved.
  6.  
  7. #include "SVAEObjectsExist.h"
  8.  
  9. #include "SVEditAEUtils.h"
  10.  
  11.  
  12. #pragma segment AppleEvent
  13.  
  14.  
  15. // -----------------------------------------------------------------------
  16. //    Name:         DoObjectsExist
  17. //    Purpose:    Handles the kAEDoObjectsExist AppleEvent. Basically just
  18. //                tries to resolve the object to see if it exists.
  19. // -----------------------------------------------------------------------
  20.  
  21. pascal OSErr DoObjectsExist(const AppleEvent    *theAppleEvent,
  22.                                     AppleEvent    *reply, 
  23.                                     long        handlerRefCon)
  24. {
  25. #pragma unused (handlerRefCon)
  26.  
  27.     AEDesc            directObject = {typeNull, NULL},
  28.                     directDesc = {typeNull, NULL},
  29.                     replyDesc = {typeNull, NULL};
  30.     long            itemCount;
  31.     Boolean           exists;
  32.     OSErr             existsErr,
  33.                     err;
  34.             
  35.     err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeWildCard, &directObject);
  36.  
  37.     err = GotRequiredParams(theAppleEvent);
  38.     if (noErr != err) goto done;
  39.  
  40.     if (typeNull == directObject.descriptorType)
  41.         exists = true;        // Yes, our application does exist?????
  42.     else
  43.     {
  44.         existsErr = AEResolve(&directObject, kAEIDoMinimum, &directDesc);
  45.         
  46.         if (noErr == existsErr)
  47.         {
  48.             if (typeAEList == directDesc.descriptorType)    // If it's a list then objects
  49.             {                                                // exist only if the list
  50.                 err = AECountItems(&directDesc, &itemCount);// is not empty.
  51.                 if (noErr != err) goto done;
  52.  
  53.                 if (itemCount)
  54.                     exists = true;
  55.                 else
  56.                     exists = false;
  57.             }
  58.             else
  59.                 exists = true;                                // Otherwise it resolved
  60.         }                                                    // so it exists.
  61.         else
  62.             exists = false;
  63.     }
  64.     
  65.     err = AECreateDesc(typeBoolean, (Ptr)&exists, sizeof(exists), &replyDesc);
  66.     if (noErr != err) goto done;
  67.     
  68.     err = AddResultToReply(&replyDesc, reply, err);
  69.     
  70. done:
  71.     if (directObject.dataHandle)
  72.         AEDisposeDesc(&directObject);
  73.     if (directDesc.dataHandle)
  74.         AEDisposeDesc(&directDesc);
  75.     if (replyDesc.dataHandle)
  76.         AEDisposeDesc(&replyDesc);
  77.         
  78.     return(err);
  79. } // DoObjectsExist
  80.